package com.alm.web.controller.alm.devinfohome;

import com.alm.common.core.controller.BaseController;
import com.alm.common.core.domain.AjaxResult;
import com.alm.handle.core.domain.entity.rq.DevInfoMacRq;
import com.alm.handle.core.domain.entity.rq.ModeChangeRq;
import com.alm.handle.service.ISysDevCurrentDataService;
import com.alm.handle.service.ISysDevInfoHomeService;
import com.alm.handle.service.ISysDevInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/alm/dev/home")
public class AlmDevInfoHomeController extends BaseController {

    @Autowired
    private ISysDevInfoHomeService sysDevInfoHomeService;

    @Autowired
    private ISysDevCurrentDataService sysDevCurrentDataService;

    @Resource
    private ISysDevInfoService devInfoService;

    @PreAuthorize("@ss.hasRole('common')")
    @GetMapping(value = "/findDevInfoByMac/{devId}")
    public AjaxResult findDevInfoByMac(@PathVariable String devId) {
        return success(sysDevCurrentDataService.findCacheByMac(devId));
    }

    /**
     * 查询首页的图表
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @GetMapping(value = "/findDevHomePageChartTest")
    public AjaxResult findDevHomePageChart() {
        return success(sysDevCurrentDataService.findHomePageCharts());
    }


    /**
     * 查询首页的图表
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping(value = "/findDevHomePageChart")
    public AjaxResult findDevHomePageChartTest(@RequestBody DevInfoMacRq rq) {
        return success(sysDevCurrentDataService.findHomePageCharts(rq));
    }

    /**
     * 获取在线设备mac地址的下拉框
     */
    @PreAuthorize("@ss.hasRole('common')")
    @GetMapping("/getOnlineMac")
    public AjaxResult getOnlineMac() {
        return success(devInfoService.getOnlineMac());
    }

    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("/changePollingMode")
    public AjaxResult changePollingMode(@RequestBody ModeChangeRq rq) {
        AjaxResult res = devInfoService.changepollingMode(rq);
        return res;
    }

}
